package com.twoGroup.boot.controller;

import com.twoGroup.boot.pojo.GoodsAndShopAndGoodsTypeAndGoodsBrand;
import com.twoGroup.boot.pojo.GoodsImg;
import com.twoGroup.boot.pojo.ResultDate;
import com.twoGroup.boot.pojo.ShopAndGoods;
import com.twoGroup.boot.service.ClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/client")
@Api(tags = "查询商品接口")
public class ClientController {
    public static Logger logger = LoggerFactory.getLogger(ClientController.class);
    @Resource
    private ClientService clientService;
    //通过点击店铺名称也就是通过店铺Id查询到店铺以及店铺下的各种商品
    @ApiOperation(value = "查询" ,notes = "通过xxx查询")
    @PostMapping("/findGoodsByClickShopId")
    public ModelAndView findGoodsByClickShopId(Model model, int shopId) {
        ModelAndView mv = new ModelAndView();
        logger.info(String.valueOf(shopId));
        List<ShopAndGoods> goodsList = clientService.findGoodsByClickShopId(shopId);
        String msg = "添加失败!!!";
        if (goodsList!=null) {
            msg = "查询成功";
        }
        model.addAttribute("goodsList",goodsList);

        mv.addObject("msg", goodsList + "," + msg);
        logger.info(String.valueOf(goodsList));
        mv.setViewName("/pagesFel/shopFront");
        return mv;
    }
    @ApiOperation(value = "通过id查询商品的详情信息")
    @ApiImplicitParam(name = "goodsId",value = "商品id")
    @ResponseBody
    @GetMapping("/findGoodsBygoodsId")
public ResultDate findGoodsByGoodsId(int goodsId){
        Map<String, Object> map = clientService.queryGoodsByGoodsId(goodsId);
        return  ResultDate.success("请求成功！",map);
 }
}
